package org.example.xiaomi.util;

import cn.hutool.core.io.resource.ClassPathResource;
import com.alibaba.druid.pool.DruidDataSource;
import org.sql2o.Sql2o;

import java.io.IOException;
import java.util.Properties;

public class DbUtil {
    private static DruidDataSource ds;
    private static Sql2o sql2o;

    static {
        ds = new DruidDataSource();
        ClassPathResource classPathResource = new ClassPathResource("druid.properties");
        Properties properties = new Properties();
        try {
            properties.load(classPathResource.getStream());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        ds.configFromPropeties(properties);
        sql2o = new Sql2o(ds);
    }
    public static Sql2o getSql2o() {
        return sql2o;
    }
}
